package com.imooc.controller;

import com.imooc.base.BaseInfoProperties;
import com.imooc.bo.VlogBo;
import com.imooc.enums.YesOrNo;
import com.imooc.grace.result.GraceJSONResult;
import com.imooc.service.VlogService;
import com.imooc.utils.PagedGridResult;
import com.imooc.vo.IndexVlogVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("vlog")
@Api(tags = "视频业务接口")
public class VlogController extends BaseInfoProperties {

        @Autowired
        private VlogService vlogService;

        @PostMapping("publish")
        public GraceJSONResult publish(@RequestBody VlogBo vlogBo){
            vlogService.createVlog(vlogBo);
            return GraceJSONResult.ok();
        }
        @GetMapping("indexList")
        public GraceJSONResult indexList(@RequestParam(defaultValue = "") String search ,@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")  Integer pageSize){
          if (page == null){
              page = COMMON_START_PAGE;
          }
          if (pageSize == null){
              pageSize  =COMMON_PAGE_SIZE;
          }

            PagedGridResult gridResult = vlogService.getIndexVlogList(search, page, pageSize);
            return  GraceJSONResult.ok(gridResult);
        }

        @GetMapping("detail")
        public GraceJSONResult detail(@RequestParam(defaultValue = "") String userId,@RequestParam String vlogId){

            return GraceJSONResult.ok(vlogService.getVlogDetailById(vlogId));
        }
        @PostMapping("changeToPrivate")
        public GraceJSONResult changeToPrivate(@RequestParam String userId,
                                               @RequestParam String vlogId){
            vlogService.changeToPrivate(userId, vlogId, YesOrNo.YES.type);
            return  GraceJSONResult.ok();
        }
        @PostMapping("changeToPublic")
        public GraceJSONResult changeToPublic(@RequestParam String userId,
                                              @RequestParam String vlogId){
            vlogService.changeToPrivate(userId, vlogId, YesOrNo.NO.type);
            return  GraceJSONResult.ok();
         }
}
